/**
 * 
 */
package javapop.framework.generic;

import javapop.framework.generic.tool.GrammarVisitor;
import javapop.utils.Quintuple;

/**
 * @author hakim
 *
 */
public class GExprOperator implements GrammarTree {

	public enum Assoc { NONE, LEFT , RIGHT };
	public enum Type { PREFIX, INFIX, POSTFIX }; 
	
	private String parser;
	private Type type;
	private Assoc assoc;
	private int prio;
	private GParser operator;
	
	/**
	 * @param content 
	 * 
	 */
	public GExprOperator(Quintuple<String, String, String, String, GParser> content) {
		//@expr_operator(logicarith,prefix,none,90, literal("!"));
		parser = content.getFirst();
		type = Type.valueOf(content.getSecond().toUpperCase());
		assoc = Assoc.valueOf(content.getThird().toUpperCase());
		prio = Integer.parseInt(content.getFourth());
		operator = content.getFifth();
	}


	/**
	 * @return the parser
	 */
	public String getParser() {
		return parser;
	}

	/**
	 * @return the type
	 */
	public Type getType() {
		return type;
	}

	/**
	 * @return the assoc
	 */
	public Assoc getAssoc() {
		return assoc;
	}

	/**
	 * @return the prio
	 */
	public int getPrio() {
		return prio;
	}

	/**
	 * @return the operator
	 */
	public GParser getOperator() {
		return operator;
	}

	@Override
	public <T,R,E extends Exception> T visit(GrammarVisitor<T,R, E> g) throws E{
		return g.visit(this);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("@expr_operator(");
		sb.append(parser);
		sb.append(",");
		sb.append(type);
		sb.append(",");
		sb.append(assoc);
		sb.append(",");
		sb.append(prio);
		sb.append(",");
		sb.append(operator);
		sb.append(");");
		return sb.toString();
	}
}
